package com.ibeeking.found.auth.api.feign.fallback;

import com.ibeeking.found.auth.api.common.query.LogoutAuthQuery;
import com.ibeeking.found.auth.api.common.query.LoginAuthQuery;
import com.ibeeking.found.auth.api.feign.CpLoginClient;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import com.ibeeking.found.auth.api.common.dto.LoginCpUserDTO;
/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class CpLoginFallbackFactory implements FallbackFactory<CpLoginClient> {
    @Override
    public CpLoginClient create(Throwable throwable) {
        return new CpLoginClient() {

            @Override
            public ResponseResult<LoginCpUserDTO> queryLoginCpUser(LoginAuthQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询用户失败。", null);
            }

            @Override
            public ResponseResult<Boolean> logout(LogoutAuthQuery param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "用户退出登录失败。", false);
            }

            @Override
            public ResponseResult<LoginCpUserDTO> queryUserByOpenId(String openId) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "登录用户信息失败。", null);
            }

            @Override
            public ResponseResult<LoginCpUserDTO> queryUserByMobileOpenId(LoginAuthQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "验证码登录用户信息失败。", null);
            }
        };
    }
}
